﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using YFIN.View.ViewModels;
using YFIN.View.BankAccountServiceRef;

namespace YFIN.View.Lockbox
{
    public partial class Account : UserControl
    {
        AccountVM _avm;
        public Account()
        {
            InitializeComponent();
            _avm = new AccountVM();
            DataContext = _avm;
        }

        private void cbRowDetailsVis_SelectionChanged(object sender, RoutedEventArgs e)
        {
            ComboBox cb = sender as ComboBox;
            ComboBoxItem cbi = cb.SelectedItem as ComboBoxItem;
            if (this.MainDataGrid != null)
            {
                if (cbi.Content.ToString() == "Selected Row (Default)")
                    MainDataGrid.RowDetailsVisibilityMode = DataGridRowDetailsVisibilityMode.VisibleWhenSelected;
                else if (cbi.Content.ToString() == "None")
                    MainDataGrid.RowDetailsVisibilityMode = DataGridRowDetailsVisibilityMode.Collapsed;
                else if (cbi.Content.ToString() == "All")
                    MainDataGrid.RowDetailsVisibilityMode = DataGridRowDetailsVisibilityMode.Visible;
            }
        }
        // Freeze the row details if the check box is checked.
        private void cbFreezeRowDetails_Changed(object sender, RoutedEventArgs e)
        {
            CheckBox cb = sender as CheckBox;
            if (this.MainDataGrid != null)
                this.MainDataGrid.AreRowDetailsFrozen = (bool)cb.IsChecked;
        }
        private void edit_Click(object sender, RoutedEventArgs e)
        {
            _avm.Update(((Button)sender).DataContext);
        }

        private void delete_Click(object sender, RoutedEventArgs e)
        {
            _avm.Account = ((Button)sender).DataContext as ModelBankAccount;
            _avm.Delete();
        }

    }
}
